package com.test.controller;

import com.test.domain.Canteen;
import com.test.enums.Page;
import com.test.enums.Replay;
import com.test.service.CanteenService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * CanteenController
 *
 * @author HY
 * 2021/05/24 8:42
 **/

@Api(tags = "食堂楼栋接口")
@RestController
@RequestMapping("/admin/Canteen")
public class CanteenController {

    @Resource
    private CanteenService canteenService;

    @PostMapping("/insert")
    @ApiOperation(value = "添加Canteen（食堂楼栋）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "食堂名", paramType = "body", required = true,
                    dataType = "String"),
            @ApiImplicitParam(name = "note", value = "食堂备注", paramType = "body",
                    dataType = "String"),
            @ApiImplicitParam(name = "address", value = "食堂地址", paramType = "body",
                    dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code = 0, message = "请求成功"),
            @ApiResponse(code = 101, message = "必填参数不能为空"),
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")
    })
    public Replay insert(@RequestBody Canteen canteen){

        Replay replay = canteenService.insert(canteen);
        return replay;
    };

    @PostMapping("/del")
    @ApiOperation(value = "删除楼栋")
    @ApiImplicitParam(name = "canteenid",
            value = "食堂id",
            paramType = "body",
            required = true,
            dataType = "Integer")
    public Replay del(int canteenid){

        Replay replay = canteenService.del(canteenid);
        return replay;
    };

    @PostMapping("/update")
    @ApiOperation("修改楼栋信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "canteenid", value = "食堂id", paramType = "body", required = true,
                    dataType = "Integer"),
            @ApiImplicitParam(name = "name", value = "食堂名", paramType = "body",
                    dataType = "String"),
            @ApiImplicitParam(name = "note", value = "食堂备注", paramType = "body",
                    dataType = "String"),
            @ApiImplicitParam(name = "address", value = "食堂地址", paramType = "body",
                    dataType = "String")
    })
    public Replay update(@RequestBody Canteen canteen){

        Replay replay = canteenService.update(canteen);
        return replay;
    };

    @GetMapping("/select")
    @ApiOperation("查询食堂楼栋")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "食堂名", paramType = "body",
                    dataType = "String"),
            @ApiImplicitParam(name = "note", value = "食堂备注", paramType = "body",
                    dataType = "String"),
//            @ApiImplicitParam(name = "address", value = "食堂地址", paramType = "body",
//                    dataType = "String"),
            @ApiImplicitParam(name = "page", value = "分页页码", paramType = "body", required = true,
                    dataType = "String"),
            @ApiImplicitParam(name = "limit", value = "分页大小", paramType = "body", required = true,
                    dataType = "String")
    })
    public Replay select(@RequestParam  Canteen canteen,@RequestParam   Page page) {

        Replay replay = canteenService.select(canteen, page);
        return replay;
    };
}
